package com.aaa.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/5/30 10:31
 * @description：字符编码过滤器
 * @modified By：
 * @version: 1.0
 */
@WebFilter(urlPatterns = "/*")
public class EncodeFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
      //设置请求的字符编码
          servletRequest.setCharacterEncoding("UTF-8");
          //设置响应的字符编码
        servletResponse.setCharacterEncoding("UTF-8");
        //放行
        filterChain.doFilter(servletRequest,servletResponse);

    }

    @Override
    public void destroy() {

    }
}
